package com.wtwd.device.handler.processimpl;

import com.wtwd.device.annotation.MsgType;
import com.wtwd.device.constant.Constant;
import com.wtwd.device.constant.MsgTypeEnum;
import com.wtwd.device.handler.MsgHandlerFactory;
import com.wtwd.device.handler.ProcessMessageHandler;
import com.wtwd.device.mqtentity.MessageBase;
import com.wtwd.device.netty.LocalSessions;
import com.wtwd.device.properties.MqProperties;
import com.wtwd.device.protocol.AppProtocol;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@MsgType(MsgTypeEnum.APP_GENERAL_CMD)
public class GeneralCmdHandler implements ProcessMessageHandler {
    @Override
    public AppProtocol processMsg(AppProtocol appProtocol, Channel channel) {
        if (LocalSessions.getDeviceLoginSession(appProtocol.getImei()) == null) {
            //设备未登录
            log.error("设备未登录异常{}-{}", appProtocol.toString());
            return null;
        }
        MsgHandlerFactory.getMqSendMessage()
                .push(
                        MessageBase.builder()
                                .deviceKey(appProtocol.getImei())
                                .appProtocol(appProtocol)
                                .form(MqProperties.getAppTopic())
                                .type(Constant.APP_MSG)
                                .build());
        return null;
    }
}
